package com.jiayan.controller;

import com.jiayan.model.EbProduct;
import com.jiayan.model.EbProductCategory;
import com.jiayan.service.GoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @RequestMapping("/list")
    public String list(Model model){
        return "goods";
    }


    @RequestMapping("/detail")
    public String detail(Model model,Integer pid){//alt+enter
        System.out.println("进入EbProductController的detail方法，pid=="+pid);
        //TODO 1.调用service根据ID获取商品
        EbProduct goodsDetail = goodsService.detail(pid);
        Map<String, EbProductCategory> resultCateMap=goodsService.linkedCateByProduct(pid);

        //TODO 2.绑定到model---数据
        model.addAttribute("goodsDetail",goodsDetail);

        model.addAttribute("cateMap",resultCateMap);

        System.out.println("detail=="+goodsDetail);
        //TODO  3.返回view--html
        return "goods";//templates/product-view.html
    }
}
